home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
034a
/
twview82.zip
/
PORTDISP.INC
< prev
next >
Wrap
Text File
|
1991-02-04
|
7KB
|
203 lines
function compatible( i1, i2 : stuff; greed : boolean ) : boolean;
{ if each sells something the other buys; if greed is true, only org/equip
trades. }
begin
if i2 = -1 then
compatible := false
else if not greed then
case i1 of
Class0, 0, 7 : compatible := false;
1 : compatible := i2 in [2, 4, 6];
2 : compatible := i2 in [1, 4, 5];
3 : compatible := i2 in [4, 5, 6];
4 : compatible := i2 in [1, 2, 3];
5 : compatible := i2 in [2, 3, 6];
6 : compatible := i2 in [1, 3, 5];
end {case}
else
case i1 of
Class0, 0, 1, 6, 7 : compatible := false;
2, 3 : compatible := i2 in [4,5];
4, 5 : compatible := i2 in [2,3];
end; {case}
end;
function deal( good1, good2 : stuff ) : string;
{ Port type "good1" selling to port type "good2" }
const
ND = 'no deal';
F = 'Fuel Ore';
O = 'Organics';
Q = 'Equipment';
any = 'anything';
begin
deal := ND;
case good1 of
Class0, 0 : ; {error}
1 : if good2 in [0,2,4,6] then deal := F;
2 : if good2 in [0,1,4,5] then deal := O;
3 : if good2 in [0,4] then deal := O + ' or ' + F
else if good2 in [1,5] then deal := O
else if good2 in [2,6] then deal := F;
4 : if good2 in [0,1,2,3] then deal := Q;
5 : if good2 in [0,2] then deal := Q + ' or ' + F
else if good2 in [1,3] then deal := Q
else if good2 in [4,6] then deal := F;
6 : if good2 in [0,1] then deal := Q + ' or ' + O
else if good2 in [2,3] then deal := Q
else if good2 in [4,5] then deal := O;
7 : case good2 of
Class0,7 : ; {error}
0 : deal := any;
1 : deal := Q + ' or ' + O;
2 : deal := Q + 'or ' + F;
3 : deal := Q;
4 : deal := O + ' or ' + F;
5 : deal := O;
6 : deal := F;
end; {case 7}
end; {case}
end; {deal}
function letterOfGood( g : goods ) : char;
begin
case g of
fuel : LetterOfGood := 'F';
Organics : LetterOfGood := 'O';
Equipment : LetterOfGood := 'E';
end; {case}
end; {letterOfGood}
procedure ComputeStores( psell, pbuy : PortIndex; var f : real;
which : goods );
var
level1, level2 : integer;
begin
level1 := space.ports.data[ psell ].amts[ which ];
level2 := space.ports.data[ pbuy ].amts[ which ];
write( letterOfGood( which ), ':', level1, ' to ', level2, ' ' );
f := -minreal( -f, -minreal( level1, -level2 ) );
end; {ComputeStores}
procedure DisplayStores( psell, pbuy : PortIndex; s : string;
var f : real;
EOonly : boolean );
{ we are given two ports, and a string s that represents the goods we are
going to be trading there. For each good in s compute the minimum of
the stores we have to sell and amount to purchase, and store the maximum in f,
while also displaying the quantities the port holds. }
begin
f := 0;
if not EOonly then
if pos( 'Fuel', s ) > 0 then
ComputeStores( psell, pbuy, f, Fuel );
if pos( 'Organic', s ) > 0 then
ComputeStores( psell, pbuy, f, Organics );
if pos( 'Equip', s ) > 0 then
ComputeStores( psell, pbuy, f, Equipment );
end; {DisplayStores}
procedure PortTradeFactor( s1, s2 : sector;
items12, items21 : string;
EOonly : boolean );
{ Print port information from these two ports corresponding to trading
items from 1 to 2 and from 2 to 1; compute relative factor. }
var
p1, p2 : PortIndex;
factor1, factor2 : real;
begin
p1 := PortNumber( s1 );
p2 := PortNumber( s2 );
if p1 = 0 then
writeln('No info available for ', s1 )
else if p2 = 0 then
writeln('No info available for ', s2 )
else
begin
write('Quantities: ');
DisplayStores( p1, p2, items12, factor1, EOonly);
DisplayStores( p2, p1, items21, factor2, EOonly);
writeln(' Factor: ', round( sqrt( factor1 * factor2 ) ) );
end; {else}
end; {PortTradeFactor}
procedure SearchPairs( NumPorts : integer;
logging : boolean; var h : text;
asciiDump : boolean; var f : text;
EquipOnly, ShowLevels : boolean );
var
i : integer;
s, s1 : sector;
g, g1 : stuff;
t : warpIndex;
NumPairs : integer;
PauseAt : integer;
begin
NumPairs := 0;
if ShowLevels then
PauseAt := 10
else
PauseAt := 20;
for i := 1 to NumPorts do
if space.sectors[ distances[i].s ].portType <> NotAPort then
begin
s := distances[ i ].s;
if space.sectors[s].number <> Unexplored then
for t := 1 to space.sectors[s].number do
begin
s1 := space.sectors[s].data[t];
if (space.sectors[ s1].portType <> NotAPort )
and (s < s1) and IsWarp( s1, s) then
{ must be a port; print only once; check if can get back }
if compatible( space.sectors[s].portType, space.sectors[s1].portType, EquipOnly ) then
begin
if logging then
begin
writeln( h, 'R', s );
writeln( h, 'R', s1);
end; {log}
g := space.sectors[s].portType;
g1 := space.sectors[s1].portType;
writeln('( ', s:3,' & ', s1:3, ' ) at distance ',
distances[i].d, ' trading ', deal( g, g1), ' for '
, deal( g1, g ));
if ShowLevels then
PortTradeFactor( s, s1, deal( g, g1), deal( g1, g ), EquipOnly );
if AsciiDump then
writeln(f, '( ', s:3,' & ', s1:3, ' ) at distance ',
distances[i].d, ' trading ', deal( g, g1), ' for '
, deal( g1, g ));
NumPairs := NumPairs + 1;
if numPairs mod PauseAt = 0 then
if not prompt('more? ') then
exit;
end; {if if}
end; {for t}
end; {if}
end; {SearchPairs}
procedure pairport;
var
QuantInfo,
Greedy : boolean;
NumPorts : integer;
AsciiDump,
loggit : boolean;
h, fp : text;
begin
SortPorts( NumPorts );
QuantInfo := prompt('Do you want to see port quantity information? ');
greedy := prompt('Do you want to only see Equip/Organic trades? ');
loggit := LogToDisk( h,
'Do you want to log the results in a format suitable for upload? ' );
AsciiDump := LogToDisk( fp,
'Do you want an echo of the results to an ascii file? ');
SearchPairs( NumPorts, Loggit, h, AsciiDump, fp, greedy, QuantInfo );
if loggit then
close( h );
if AsciiDump then
close( fp );
end; {pair ports}